<template>
	<view class="content">
		<view style=" width: 100vw; height: 10vh;">
			<view style="width: 100%; height: 100%; display: flex;justify-content: center;align-items: center;">
				<view style="font-size: 64rpx;">一寻视康后台管理</view>
			</view>
		</view>
		<view style="display: flex;">
			<view style=" width: 10vw;height: 90vh; min-width: 200rpx;" v-if="this.mainpage!=''">
				<scroll-view scroll-y="true" style="height: 90vh;">
					<uni-collapse>
						<uni-collapse-item title="组织机构" :open="true">
							<view class="menuitem" @click="menuclick('usercenter','会员中心')">按省市地划分</view>
						</uni-collapse-item>
						<uni-collapse-item title="会员管理" :open="true">
							<view class="menuitem" @click="menuclick('memberManage','公域会员管理')">公域会员管理</view>
							<view class="menuitem" @click="menuclick('memberManage','会员信息')">会员信息</view>
						</uni-collapse-item>
						<uni-collapse-item title="加盟管理" :open="true">
							<view class="menuitem" @click="menuclick('corpMemberManage','加盟店管理')">加盟店管理</view>
						</uni-collapse-item>
						<uni-collapse-item title="短信营销" :open="true">
						</uni-collapse-item>
						<uni-collapse-item title="参数设置" :open="true">
							<view class="menuitem" @click="menuclick('pointsAboutSetup')">消费发放积分设置</view>
						</uni-collapse-item>
						<uni-collapse-item title="操作日志" :open="true">
							<view class="menuitem" @click="menuclick('balanceLog')">积分代金券日志</view>
						</uni-collapse-item>
						<uni-collapse-item title="权限管理" :open="true">
							<view class="menuitem" @click="menuclick('editpassword')">修改密码</view>
							<view class="menuitem" @click="logout">退出登录</view>
						</uni-collapse-item>

					</uni-collapse>
				</scroll-view>
			</view>
			<view style=" width: 85vw;height: 90vh;">
				<login v-if="mainpage==''" @submit="menuclick"></login>
				<corpMemberManage v-if="mainpage=='corpMemberManage'" />
				<memberManage v-if="mainpage=='memberManage'" :memberManageMembertype="memberManageMembertype"
					@popwindow="popwindow" />
				<pointsAboutSetup v-if="mainpage=='pointsAboutSetup'"></pointsAboutSetup>
				<balanceLog v-if="mainpage=='balanceLog'"></balanceLog>

			</view>
		</view>
		<uni-popup ref="popupwindow">
			<view class="popwindowstyle">
				<balanceRecharge v-if="popwindowname=='balanceRecharge'" @operate="balanceRechargeOperate">
				</balanceRecharge>
				<RechargedConsumption v-if="popwindowname=='RechargedConsumption'" @operate="balanceRechargeOperate">
				</RechargedConsumption>
				<unRechargedConsumption v-if="popwindowname=='unRechargedConsumption'"
					@operate="balanceRechargeOperate">
				</unRechargedConsumption>
				<pointsDec v-if="popwindowname=='pointsDec'" @operate="balanceRechargeOperate">
				</pointsDec>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import {
		postrequest
	} from '../../common/apis.js';
	export default {
		data() {
			return {
				username: uni.getStorageSync('username', 'username'),
				password: uni.getStorageSync('password', 'password'),
				currentPage: uni.getStorageSync('currentPage', 'memberManage'),
				currentPageName: '',
				mainpage: '',
				memberManageMembertype: '会员管理',
				popwindowname: '', //弹出功能页面名称
			}
		},
		onLoad() {

		},
		mounted() {
			if (this.username != '' && this.password != '') {
				this.loginsubmit()
			}
		},
		methods: {
			balanceRechargeOperate(v) {
				let that = this
				if (v == 'closeme') {
					that.$refs.popupwindow.close()
					let mainpage = that.mainpage
					that.mainpage = ''
					setTimeout(() => {
						that.mainpage = mainpage
						// 在这里执行需要延时的代码
					}, 100);
				}
				if (v == 'cancle') {
					that.$refs.popupwindow.close()

				}
			},
			logout() {
				uni.removeStorageSync('username')
				uni.removeStorageSync('password')
				this.mainpage = ''
			},
			popwindow(v) {
				console.log(v)
				this.popwindowname = v
				this.$refs.popupwindow.open('center')
			},
			menuclick(e, n) {
				console.log(e)
				this.mainpage = e
				this.currentPageName = n
				if (n == '公域会员管理') {
					this.memberManageMembertype = n
				} else {
					this.memberManageMembertype = '会员管理'
				}
				this.$forceUpdate()
			},
			loginsubmit() {
				console.log('loginsubmit')
				let data = {
					username: this.username,
					password: this.password,
				}
				let url = 'https://www.jsyufang.com/yiXun/api/adminlogin/index.asp'
				let errmessage = '调用登录接口失败'
				postrequest(url, data, errmessage, true)
					.then((res) => {
						console.log(res)
						if (res.data.code == 0) {
							this.mainpage = uni.getStorageSync('currentPage', 'memberManage')
							console.log(this.mainpage)
						}
					})
			}
		}
	}
</script>

<style>
	.left {
		height: 93vh;
		width: 10vw;
		min-width: 400rpx;
		background-color: white;
	}

	.hover-box {
		padding: 20px;
		background-color: #f0f0f0;
		margin: 10px;
		text-align: center;
		transition: background-color 0.3s;
		border-radius: 10rpx;
	}

	.hover-box:hover {
		background-color: #bada55;
		cursor: pointer;
	}

	.menuitem {
		padding-left: 50rpx;
		padding-top: 10rpx;
		padding-bottom: 10rpx;
	}

	.popwindowstyle {
		width: 1000rpx;
		height: auto;
		max-height: 90vh;
		background-color: white;
		border-radius: 30rpx;
		padding: 30rpx;
		justify-content: center;
		overflow-y: auto;
	}
</style>